using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Text.RegularExpressions;
using Castle.MonoRail.Framework;
using DotNet_Common;
using res.Models;


namespace res.Controllers
{
    public class DocController : SmartDispatcherController
    {

        public void index()
        {
            
        }



        public void list()
        {
            string keyword = Query["slk_title"];
            PropertyBag["slk_title"] = keyword;

            if (keyword !=null && keyword!= "")
            {
                string keywordutf = HttpUtility.UrlEncode(keyword, System.Text.Encoding.UTF8);
                keyword = HttpUtility.UrlEncode(keyword, System.Text.Encoding.GetEncoding("gb2312"));

                string pn = Query["pn"];
                if (pn == "") { pn = "0"; }
                int pnx = Convert.ToInt16(pn);

                string url = "http://www.baidu.com/baidu?q1=" + keyword + "&ft=all&&rn=10&pn=" + pnx.ToString();
                
                //Response.Write(url);

                BaiduGet getdata = new BaiduGet();
                SeResultList re = getdata.GetSeResult(url, "doc");
                string recount = getdata.recount;



                string pageurl = Regex.Replace(re.pagetext, @"s\?([0-9]+)", "list.aspx?slk_title=" + keywordutf + "&pn=$1");

                PropertyBag["datas"] = re.list;

                PropertyBag["pages"] = pageurl;

                PropertyBag["recount"] = recount;
            }
        }


        public void info()
        {

        }

    }
}